function HighLight(TheTR, sClassName)
{
    TheTR.className = sClassName;
}

function ShowDiv(sDivName, sFocusName)
{
    var MItem = document.getElementById(sDivName);
    if(MItem)
    {
        MItem.style.display = "block";
        var objFocus = document.getElementById(sFocusName);
        if(objFocus)
        {
            objFocus.focus();
        }
    }
}

function HideDiv(sDivName)
{
    var MItem = document.getElementById(sDivName);
    if(MItem)
    {
        MItem.style.display="none";
    }
}

function ToDayString()
{
	// Day of week name
	var arrDayOfWeek = new Array();
    arrDayOfWeek[0] = MYSCRIPTS_SUN;
    arrDayOfWeek[1] = MYSCRIPTS_MON;
    arrDayOfWeek[2] = MYSCRIPTS_TUE;
    arrDayOfWeek[3] = MYSCRIPTS_WED;
    arrDayOfWeek[4] = MYSCRIPTS_THU;
    arrDayOfWeek[5] = MYSCRIPTS_FRI;
    arrDayOfWeek[6] = MYSCRIPTS_SAT;

    today = new Date();
    weekday = 	today.getDay();
    date 	= 	today.getDate();
    if(date < 10)
    {
        date = "0" + date;
	}

    month 	= 	today.getMonth() + 1;
	if(month < 10)
	{
	    month = "0" + month;
	}

	year	=	today.getYear();
    if(year <= 1888)
    {
        year = 1900 + year;
	}

    var sDate = "";
    sDate = arrDayOfWeek[weekday] + ", " + date + "/" + month + "/" + year;
	return(sDate);
}

// Ham set gia tri cho doi tuong (an toan)
function SetObjValue(sObjID, sVal)
{
	var tmpObj = document.getElementById(sObjID);
	if(tmpObj)
	{
		tmpObj.value = sVal;
		return(true);
	}

	return(false);
}

// Ham set innerHTML cho doi tuong (an toan)
function SetObjInnerHTML(sObjID, sVal)
{
	var tmpObj = document.getElementById(sObjID);
	if(tmpObj)
	{
		tmpObj.innerHTML = sVal;
		return(true);
	}

	return(false);
}

// Ham set gia tri cho doi tuong (an toan)
function SetObjHref(sObjID, sVal)
{
	var tmpObj = document.getElementById(sObjID);
	if(tmpObj)
	{
		tmpObj.href = sVal;
		return(true);
	}
	return(false);
}

// Ham lay gia tri cau doi tuong (an toan)
function GetObjValue(sObjID, sDefVal)
{
	var tmpObj = document.getElementById(sObjID);
	if(tmpObj)
	{
		return(tmpObj.value);
	}
	return(sDefVal);
}

// Ham set thuoc tinh readonly cua 1 doi tuong
function SetObjReadOnly(sObjID, bStatus)
{
	var tmpObj = document.getElementById(sObjID);
	if(tmpObj)
	{
		// Kiem tra va validate bStatus
		if(bStatus != false)
		{
			bStatus = true;
		}
		tmpObj.readOnly = bStatus;
		return(true);
	}
	else
	{
		//alert('Khong tim thay doi tuong');
	}
	return(false);
}

// Ham lay set disable 1 doi tuong
function SetObjDisable(sObjID, bStatus)
{
	var tmpObj = document.getElementById(sObjID);
	if(tmpObj)
	{
		// Kiem tra va validate bStatus
		if(bStatus != false)
		{
			bStatus = true;
		}
		tmpObj.disabled = bStatus;
		return(true);
	}
	return(false);
}

// Ham lay set focus 1 doi tuong
function SetObjFocus(sObjID)
{
	var tmpObj = document.getElementById(sObjID);
	if(tmpObj)
	{
		tmpObj.focus();
		return(true);
	}
	return(false);
}

// Ham set invisible 1 doi tuong
function SetObjInvisble(sObjID, bStatus)
{
	if(bStatus)
	{
		bStatus = "";
	}
	else
	{
		bStatus = "none";
	}
	var tmpObj = document.getElementById(sObjID);
	if(tmpObj)
	{
		tmpObj.style.display = bStatus;
		return(true);
	}
	return(false);
}

function AddOption(sID, sVal, sText)
{
    //using W3C syntax add Options for SELECT
    var objTmp = document.getElementById(sID);
    if(!objTmp)
    {
    	alert(MYSCRIPTS_NON_OBJ);
    	return(false);
    }
    var objOption = document.createElement("OPTION");
    objOption.text = sText;
    objOption.value = sVal;
    objTmp.options.add(objOption);
    return(true);
}

function ResetCombo(sID)
{
	var objTmp = document.getElementById(sID);
	if( !(objTmp && objTmp.options) )
	{
		// Loi khi lay doi tuong
		return(false);
	}
	if(objTmp.options.length)
	{
		objTmp.options.length = 0;
		return(true);
	}
}

// Ham lay ngay hien hanh tra ve theo dinh dang: dd/mm/yyyy
function GetCurDate()
{
	today = new Date();
    date 	= 	today.getDate();
    if(date < 10)
    {
        date = "0" + date;
	}

    month 	= 	today.getMonth() + 1;
	if(month < 10)
	{
	    month = "0" + month;
	}

	year	=	today.getYear();
    if(year <= 1888)
    {
        year = 1900 + year;
	}

    var sDate = "";
    sDate = date + "/" + month + "/" + year;
	return(sDate);
}

// Ham lay doi tuong javascript de add vao div dung cho truong hop doc du lieu tu ngoai gan vao div va chay chuong script
function AddDivScript(objID)
{
	var tmpObj = document.getElementById(objID);
	if(!tmpObj)
	{
		alert(MYSCRIPTS_NON_OBJ);
		return(false);
	}
	var d = tmpObj.getElementsByTagName("script")
	var t = d.length
	for (x=0; x<t; x++)
	{
		var newScript = document.createElement('script');
		newScript.type = "text/javascript";
		newScript.text = d[x].text;
		if(d[x].parentNode)
		{
			d[x].parentNode.appendChild(newScript);
			//eval(d[x].text);
			//alert(d[x].parentNode)
		}
		//tmpObj.appendChild (newScript);
		//eval(d[x].text);
	}
	return(true);
}
// Het Ham lay doi tuong javascript de add vao div

function GotoPage(sUrl)
{
	window.location.href=sUrl;
}

// Tao cac doi tuong lich
function CreateCalObject(objID, imgID)
{
	var theObj = document.getElementById(objID);
	if(!theObj)
	{
		tmpObj = document.getElementById(imgID);
		if(tmpObj)
		{
			tmpObj.style.display = "none";
		}
		return(false);
	}
	var objRet = new calendar2(theObj);
	if(!objRet)
	{
		tmpObj = document.getElementById(imgID);
		if(tmpObj)
		{
			tmpObj.style.display = "none";
		}
		return(false);
	}
	objRet.year_scroll = false;
	objRet.time_comp = false;
	return(objRet);
}// Het ham tao doi tuong lich

// Ham CheckAll: check vao 1 check box de check tat ca cac checkbox cung ten trong form
function FCheckAll(sFormID, sCheckID, sCheckName)
{
	var tmpCheck = document.getElementById(sCheckID);
	if(!tmpCheck)
	{
		alert(MYSCRIPTS_NON_CHECKBOX);
		return(false);
	}

	var tmpObj = document.getElementById(sFormID);
	if(!tmpObj)
	{
		alert(MYSCRIPTS_NON_FORM);
		return(false);
	}
	var n = tmpObj.length;
	for(i = 0; i < n; i++)
	{
		if(tmpObj[i].name == sCheckName)
		{
			tmpObj[i].checked = tmpCheck.checked;
		}
	}
	return(true);
}
// Het ham CheckAll

function DisableAll(sFormID, bDisable)
{
	// Gan gia tri mac dinh cho bien bDisable trong truong hop khong truyen tham so
	if(typeof(bDisable) == 'undefined')
	{
		bDisable = true;
	}
	// Kiem tra va hop le hoa gia tri cho tham so bDisable
	if(bDisable != true)
	{
		bDisable = false;
	}

	var tmpObj = document.getElementById(sFormID);
	if(!tmpObj)
	{
		//alert('Khong tim thay form');
		return(false);
	}
	var n = tmpObj.length;
	n = tmpObj.childNodes.length;
	/*
	for(key in tmpObj.childNodes)
	{
		alert(key);
	}*/
	for(i = 0; i < n; i++)
	{
		if(tmpObj.childNodes[i].nodeType == 1)
		{
			tmpObj.childNodes[i].disabled = bDisable;
			alert(tmpObj.childNodes[i].hasChildNodes());
		}

		/*
		for(key in tmpObj.childNodes[i])
		{
			alert(key);
		}*/
		//alert(tmpObj.childNodes[i].nodeType);
	}
	return(true);
}

function DisableAll2(objThis, bDisable)
{
	// Gan gia tri mac dinh cho bien bDisable trong truong hop khong truyen tham so
	if(typeof(bDisable) == 'undefined')
	{
		bDisable = true;
	}
	// Kiem tra va hop le hoa gia tri cho tham so bDisable
	if(bDisable != true)
	{
		bDisable = false;
	}

	if(typeof(objThis.nodeType) == 'undefined')
	{
		return(true);
	}
	if(objThis.nodeType == 3)
	{
		return(true);
	}

	if(!objThis.hasChildNodes())
	{
		if(objThis.nodeType != 3)
		{
			objThis.disabled = bDisable;
			return(true);
		}
	}
	else
	{
		for( key in objThis.childNodes)
		{
			if(objThis.childNodes[key].nodeType != 3)
			{
				DisableAll2(objThis.childNodes[key], bDisable);
			}
		}
	}
	return(true);
}
// Cac ham meu dac thu gi cua may cha ne
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function P7_hideEl(evt) { //v1.7 by PVII-www.projectseven.com
 var b,r,m=false;if(document.layers){b=evt.target;if(b.p7aHide){
 b.visibility="hidden";}else{routeEvent(evt);}
 }else if(document.all&&!window.opera){b=event.srcElement;while(b){
 if(b.p7aHide){break;}b=b.parentElement;}if(!b.contains(event.toElement)){
 b.style.visibility="hidden";}}else if(document.getElementById){
 b=evt.currentTarget;r=evt.relatedTarget;while(r){if(b==r){m=true;
 break;}r=r.parentNode;}if(!m){b.style.visibility="hidden";}}
}

function P7_autoHide() { //v1.7 by PVII-www.projectseven.com
 var i,g;for(i=0;i<arguments.length;i++){
 if((g=MM_findObj(arguments[i]))!=null){g.p7aHide=true;if(document.layers){
 g.captureEvents(Event.MOUSEOUT);}
 if(g.addEventListener){g.addEventListener("mouseout",P7_hideEl,true);
 }else if(g.attachEvent){g.attachEvent("onmouseout",P7_hideEl);
 }else{g.onmouseout=P7_hideEl;}}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}

// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}


// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}


pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
